#include <stdio.h>
#include "CList.h"

int main()
{
    struct cListNode *head = NULL;		//创建头指针，初始化为NULL
    cListInit(&head);                   //初始化指针（可有可无）

    //1：添加数据
    for(int i = 0;i < 30;i ++)
    {
        if(i > 10)
            cListPushFront(&head,i);        //头部插入
        else
            cListPushBack(&head,i);         //尾部插入
    }
    printf("\n 1:  count:%d \n", cListNodeCount(head));    //获取链表节点数，打印
    cListPrint(head);   //打印链表

    //2：删除数据
    for(int i = 0;i < 10;i ++)
    {
        if(i > 5)
            cListPopBack(&head);        //删除尾部
        else
            cListPopFront(&head);       //头部删除
    }
    printf("\n 2:  count:%d \n", cListNodeCount(head));
    cListPrint(head);

    //3：插入数据
    cListInsert(&head,5,1111);
    cListInsertForNode(&head,head->Next->Next->Next->Next->Next,10000);
    cListInsert(&head,1000,2222);       //无效插入
    printf("\n 3:  count:%d \n", cListNodeCount(head));
    cListPrint(head);

    //4：删除指定节点
    cListErase(&head,5);
    cListEraseForNode(&head,head->Next->Next);
    cListErase(&head,1000);     //无效删除
    cListPrint(head);
    printf("\n 4:  count:%d \n", cListNodeCount(head));
    cListPrint(head);

    //5：删除所有节点
    cListDestroy(&head);
    printf("\n 5:  count:%d    ", cListNodeCount(head));
    cListPrint(head);
    return 0;
}
